<?php htmlTemplate('index/header.php')?>

<div class="nav">			
	<span class="nav_span">
	<a class="nav_home" href="<?php echo MVC_WWW_HOST;?>">&nbsp;</a>
	<a href="<?php echo MVC_WWW_HOST?>library/index">Library</a> :: 
	Add Questions
	</span>
</div>
<form method="post" action="<?php echo MVC_WWW_HOST.'quiz/save/select/1'?>" target="_blank" id="form1">
<div class="common_search_wrap" style="text-align:left">Quiz to cate:
	<select name="cate" id="cate" >            	
	<?php
	if ($cates){
		foreach ($cates as $k=>$v): 
	?>
		<option value="<?php echo $v['id']?>"><?php echo $v['name']?></option>
	<?php 
		endforeach;
		echo '<option value="0">默认分类</option>';
		}else {
		echo '<option value="0">默认分类</option>';
	}?>
	</select>
	<input type="button" class="add_btn" onclick="addCate('addcate')" />
	<span id="addcate" style="display:none;">
	<input type="text" class="input3" id="savecate"> <input type="button" class="search_submit2" onclick="saveCate()" value="Save">
	</span>
	
	<div style="float:right;padding-right:10px;width:133px;">

<input type ="submit" class="search_submit4" value="保存" />&nbsp;
<button type ="button" class="search_submit4" onclick="veiwQuiz()" >预览 </button>
</div>
</div>
<div class="lib_add_wrap">
	<table class="com_table" cellspacing="1" cellpadding="3" >			  
		<tr >
			<td class="quiz_remark" width="78px">主标题</td>
			<td colspan="3">&nbsp;<input name="sub1"  type="text" class="input7"> </td>			
		</tr>
		<tr>
			<td class="quiz_remark">副标题</td>
			<td colspan="3">&nbsp;<input name="sub2" type="text" class="input7"></td>			
		</tr>
		<tr >
			<td class="quiz_remark" >说明 </td>
			<td colspan="3">&nbsp;<input name="sub3" type="text" class="input7"> </td>			
		</tr>
		<tr >
			
			<td colspan="4" style='height:29px;'>&nbsp;
			
			</td>			
		</tr>
		
	</table>
	<div id="questions">
			
	</div>	
</div>
<div class="setans"><button type ="button" class="search_submit3" onclick="addQues()" >设置题目 </button>

</div>
</form>
<script type="text/javascript">
var qid=1;
function addQues(){
	
	var html = '<div class="ques_div" id="q'+qid+'">'
		+'<span class="ques_span">题目：<input name="p_sort_'+qid+'" type="text" class="input8" value="'+qid+'"> </span>'
		+'<span class="ques_ques">&nbsp;<input name="p_title_'+qid+'" type="text" class="input9"> </span>'
		+'<span class="ques_point">总分：<input name="p_score_'+qid+'" type="text" class="input8"> </span>'		
		+'<span>'
		+'<button type="button" class="search_submit3" onclick="getLib('+qid+')">设置题目 </button>' 
		+'<button type="button" class="search_submit2" onclick="delQues('+ "'q"+ qid+ "'"+ ',1)">删除 </button>'
		+'</span>'	
		+'</div>'
		+'<div id="qc'+qid+'"></div>';
	//alert(html);
	$("#questions").append(html);
	qid++;
}
function delQues(id,delc){
	
	if(delc){
		$("#qc"+id.substring(1)).remove();
	}
	$("#"+id).remove();
}
function addCate(id){
	$("#"+id).fadeIn();
	
}
function cback(id,items){	
	$.modal.close();
	var url = '<?php echo MVC_WWW_HOST.'library/getques.html';?>';
	$("#error").show();
	$("#error").html('loading...');	
	$.get(url,{'id':id, 'items':items},function(rs){
		$("#qc"+id).append(rs);
		$("#error").html('');
		$("#error").hide();
	})
}
function getLib(id)
{
	showFrame('<?php echo MVC_WWW_HOST.'library/simple/setid/'?>'+id,800,400);
}
function saveCate(){
	var savecate = $.trim($("#savecate").val());
	url = '<?php echo MVC_WWW_HOST;?>quiz/addcate.html';
	$.getJSON(url,{'savecate':savecate},function(data){
		alert(data.html);
		if(data.rs==1){
			var row = '<option value="'+ data.id +'">' +savecate+ '</option>';
			var tmpHtml = $("#cate").html();
			$("#cate").html(row+tmpHtml);
		}
		
	})
}
$(document).ready(function(){
	var sh=screen.height;	
	//getHtml('<?php echo MVC_WWW_HOST;?>library/questions/height/'+sh+'.html','questions');
	$('#form1').ajaxForm(function(rs) {   
	       alert(rs);  
	});
	
})

</script>		
<?php htmlTemplate('index/footer.php')?>
